﻿Public Class WfAltServico
    Inherits System.Web.UI.Page
    Dim cod_serv As New Integer

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack = False Then
            populaGv()
        End If
       
    End Sub

    Public Sub populaGv()
        Dim lista As New List(Of Servico)
        Dim objservDao As New ServicoDAO

        lista = objservDao.ListaTodos
        GvServicos.AutoGenerateColumns = False
        GvServicos.DataSource = lista
        GvServicos.DataBind()
    End Sub

    Private Sub Page_PreRender(sender As Object, e As System.EventArgs) Handles Me.PreRender
        If Session("DespLogado") Is Nothing Then
            Response.Redirect("/Screens/WF1.aspx")
        End If
    End Sub

    Protected Sub Alterar_Click(sender As Object, e As EventArgs) Handles Alterar.Click
        Try
            cod_serv = GvServicos.SelectedRow.Cells(1).Text
            Response.Redirect("WfCadServiço.aspx?cod_serv=" & cod_serv)
        Catch ex As Exception
            lbmsg.Text = "Selecione um Serviço !"
        End Try
        

    End Sub

    Protected Sub Apagar_Click(sender As Object, e As EventArgs) Handles Apagar.Click
        Try
            Dim servico As New Servico
            Dim servicoDao As New ServicoDAO

            servico.CodServ = GvServicos.SelectedRow.Cells(1).Text
            servicoDao.Deleta(servico)
            populaGv()
        Catch ex As Exception
            lbmsg.Text = "Selecione um Serviço !"
        End Try
    End Sub
End Class